<?php

/**
 * make sure this is only included once!
 */
if ( !defined("DATABASE_INCLUDED") ) {
	define("DATABASE_INCLUDED",1);
	
/**
 * 数据库接口类。
 *
 * 一个关于数据库接口类，可以通过这个类来驱动不同的数据库。
 * @package     db  (所属的模块名称)
 * @author      Jerry <jerryjiang15@163.com>
 * @version     $ID$
 */
	class DB 
	{
		/**
		 * Prefix for tables in the database
		 * @var string
		 */
		var $prefix = '';
		/**
		 * reference to a {@link Logger} object
         * @see Logger
		 * @var object Logger
		 */
		var $logger;

		/**
		 * constructor
         * 
         * will always fail, because this is an abstract class!
		 */
		function DB()
		{
			// exit("Cannot instantiate this class directly");
		}
		
		/**
		 * 获得工厂对象
         * 
         * will always fail, because this is an abstract class!
		 */
		function &getInstance()
		{
			return DBFactory::getDBConnection();
		}

		/**
		 * assign a {@link Logger} object to the database
		 * 
         * @see Logger
         * @param object $logger reference to a {@link Logger} object
		 */
		function setLogger(&$logger)
		{
			$this->logger =& $logger;
		}

		/**
		 * set the prefix for tables in the database
		 * 
         * @param string $value table prefix
		 */
		function setPrefix($value)
		{
			$this->prefix = $value;
		}
		
		/**
		 * attach the prefix.'_' to a given tablename
         * 
         * if tablename is empty, only prefix will be returned
		 * 
         * @param string $tablename tablename
         * @return string prefixed tablename, just prefix if tablename is empty
		 */
		function prefix($table_name='')
		{
			if ( $table_name != '' ) 
			{
				return $this->prefix .'_'. $table_name;
			} 
			else 
			{
				return $this->prefix;
			}
		}
	
	}

}
?>